<template>
  <div class="zong" id="charityMall">
    <!-- <h2>欢迎进入义卖商城</h2>
    <h6>本平台承诺所有义卖筹集资金都将用于公益事业</h6>-->

    <!-- 顶部左侧div开始 -->
    <div class="top">
      <div class="top_l">
        <h2>欢迎进入义卖商城</h2>

        <div class="block">
          <div class="block-menu">
            <!-- <div v-for="(item, index) in list" :key="index"> -->
            <div v-for="(item, index) in FirstCategory" :key="index">
              <a href="javascript:;" class="three-d" @click="anchorJump(index)">
                <span aria-hidden="true" class="three-d-box">
                  <span class="front">
                    {{
                    FirstCategory[index].categoryTitle
                    }}
                  </span>
                  <span class="back">点此查找{{ FirstCategory[index].categoryTitle }}</span>
                  <!-- <span class="front">{{ item.category }}</span>
                  <span class="back">{{ item.des }}等你来购</span>-->
                </span>
              </a>
            </div>
          </div>
        </div>
      </div>
      <!-- 顶部左侧div结束 -->
      <div class="top_r">
        <div class="command">
          <br />——· 今日好物推荐 ·——
          <!-- 顶部3d轮播开始 -->
          <carousel-3d
            class="carousel"
            :autoplay="true"
            :autoplayTimeout="3000"
            :display="5"
            :width="320"
            :height="200"
            :animationSpeed="1000"
          >
            <slide :index="index" v-for="(item, index) in carousel" :key="index">
              <p @click="routerTo('/detail', carousel[index].productId)">
                今日好物推荐
                <br />
                {{ carousel[index].productName }}
              </p>
              <el-image :src="carousel[index].productHomeImageUrl" class="pic"></el-image>
            </slide>
          </carousel-3d>
          <!-- <carousel-3d
          class="carousel"
          :autoplay="true"
          :autoplayTimeout="3000"
          :display="5"
          :width="320"
          :height="200"
          :animationSpeed="1000"
        >
          <slide :index="index" v-for="(item, index) in carousel" :key="index">
            <p @click="routerTo('/detail', index)">
              每日好物推荐
              <br />Lorem, ipsum dolor sit amet consectetur adipisicing elit.
              doloribus?
            </p>
            <el-image :src="carousel[index]" class="pic"></el-image>
          </slide>
          </carousel-3d>-->
          <!-- 顶部3d轮播结束 -->
        </div>
      </div>
    </div>
    <!-- 商城开始 -->
    <div>
      <!-- 滚动视差开始 -->
      <div class="parallax">
        <!-- 所有商品 -->
        <el-collapse accordion>
          <el-collapse-item>
            <template slot="title">
              <div class="bg__foo">
                所有商品，由此进入
                <div class="circle"></div>
              </div>
            </template>
            <div class="blue">
              <el-tabs type="border-card">
                <el-tab-pane label="商品">
                  <div class="row">
                    <div class="proB">
                      <div
                        class="grid-content bg-purple productBox"
                        v-for="(item, index) in payload"
                        :key="index"
                      >
                        <div class="imgbox">
                          <el-image :src="`${payload[index].productHomeImageUrl}`" class="img"></el-image>
                          <a href="javascript:;">
                            <div
                              class="black"
                              @click="
                                routerTo('/detail', payload[index].productId)
                              "
                            >
                              <span>查看详情</span>
                            </div>
                          </a>
                        </div>
                        <div class="bg-text">
                          <div class="grid-content1 bg-purple1">
                            <span>{{ payload[index].productName }}</span>
                          </div>
                          <div class="grid-content1 bg-purple1">
                            <span>单价：{{ payload[index].productPrice }}</span>
                          </div>
                          <div class="grid-content1 bg-purple1">
                            <span>商品描述：{{ payload[index].productDetail }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </el-tab-pane>
              </el-tabs>
            </div>
          </el-collapse-item>
        </el-collapse>

        <!-- 动态生成分类 -->
        <el-collapse
          accordion
          v-for="(item, index) in FirstCategory"
          :key="index"
          v-model="activeName"
        >
          <el-collapse-item>
            <template slot="title">
              <div
                :class="`bg__bar${index}`"
                :id="`anchor${index}`"
                @click="getSonCategory(FirstCategory[index].categoryId)"
              >
                {{ FirstCategory[index].categoryTitle }}，由此进入
                <div class="circle"></div>
              </div>
            </template>
            <div class="blue" v-if="categorySon!=null">
              <el-tabs type="border-card" @tab-click="handelClick" v-model="activeTab">
                <el-tab-pane
                  v-for="(item, cindex) in categorySon"
                  :key="cindex"
                  :label="`${item.categoryTitle}`"
                  :name="item.categoryId.toString()"
                >
                  <div class="row1">
                    <div class="proB">
                      <div
                        class="grid-content bg-purple productBox"
                        v-for="(item, index) in categoryById"
                        :key="index"
                      >
                        <div class="imgbox">
                          <el-image :src="`${categoryById[index].productHomeImageUrl}`" class="img"></el-image>
                          <a href="javascript:;">
                            <div
                              class="black"
                              @click="
                                routerTo(
                                  '/detail',
                                  categoryById[index].productId
                                )
                              "
                            >
                              <span>查看详情</span>
                            </div>
                          </a>
                        </div>
                        <div class="bg-text">
                          <div class="grid-content1 bg-purple1">
                            <span>{{ categoryById[index].productName }}</span>
                          </div>
                          <div class="grid-content1 bg-purple1">
                            <span>
                              单价：{{
                              categoryById[index].productPrice
                              }}
                            </span>
                          </div>
                          <div class="grid-content1 bg-purple1">
                            <span>商品描述：{{ categoryById[index].productDetail }}</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </el-tab-pane>
                <!-- <el-tab-pane
                  v-for="(item,index) in categorySon"
                  :key="index"
                  :label="`${item.categoryTitle}`"
                >这里是{{item.categoryTitle}}</el-tab-pane>-->
              </el-tabs>
            </div>
            <div class="blue" v-else>
              <div
                class="row1"
                @mouseenter="getAllProductByCategoryId(FirstCategory[index].categoryId)"
              >
                <div class="proB" v-if="categoryById!=null">
                  <div
                    class="grid-content bg-purple productBox"
                    v-for="(item, index) in categoryById"
                    :key="index"
                  >
                    <div class="imgbox">
                      <el-image :src="`${categoryById[index].productHomeImageUrl}`" class="img"></el-image>
                      <a href="javascript:;">
                        <div
                          class="black"
                          @click="
                                routerTo(
                                  '/detail',
                                  categoryById[index].productId
                                )
                              "
                        >
                          <span>查看详情</span>
                        </div>
                      </a>
                    </div>
                    <div class="bg-text">
                      <div class="grid-content1 bg-purple1">
                        <span>{{ categoryById[index].productName }}</span>
                      </div>
                      <div class="grid-content1 bg-purple1">
                        <span>
                          单价：{{
                          categoryById[index].productPrice
                          }}
                        </span>
                      </div>
                      <div class="grid-content1 bg-purple1">
                        <span>商品描述：{{ categoryById[index].productDetail }}</span>
                      </div>
                    </div>
                  </div>
                </div>
                <div v-else>
                  <h2>没有相应商品，去别处看看吧</h2>
                </div>
              </div>
            </div>
          </el-collapse-item>
        </el-collapse>

        <!-- 积分商城 -->
        <el-collapse accordion>
          <el-collapse-item>
            <template slot="title">
              <div class="bg__baz">
                积分商城，由此进入
                <div class="circle"></div>
              </div>
            </template>
            <div class="green">
              <el-tabs type="border-card">
                <el-tab-pane label="积分1">
                  <el-row
                    type="flex"
                    class="row-bg"
                    justify="space-around"
                    v-for="(item, index) in str"
                    :key="index"
                  >
                    <el-col :span="4" v-for="(item, index) in square" :key="index">
                      <div class="grid-content bg-purple">
                        <div class="imgbox1">
                          <el-image src="../assets/image/charity/product.jpg" class="img"></el-image>
                          <a href="javascript:;">
                            <div class="black" @click="routerTo('/detail', index)">
                              <!--routerTo中传入商品类别以及商品id， index假设为商品id -->
                              <span>查看详情</span>
                            </div>
                          </a>
                        </div>
                        <div>
                          <el-row :gutter="20">
                            <el-col :span="22" :offset="1">
                              <div class="grid-content1 bg-purple1">
                                <span>中国移动话费10元20元30元</span>
                              </div>
                              <div class="grid-content1 bg-purple1">
                                <span>积分：20分</span>
                              </div>
                              <div class="grid-content1 bg-purple1">
                                <span>商品描述：这里是商品描述描述描述描述描述</span>
                              </div>
                            </el-col>
                          </el-row>
                        </div>
                      </div>
                    </el-col>
                  </el-row>
                </el-tab-pane>
                <el-tab-pane label="兑换2">这里是兑换2</el-tab-pane>
                <el-tab-pane label="兑换3">这里是兑换3</el-tab-pane>
              </el-tabs>
            </div>
          </el-collapse-item>
        </el-collapse>
      </div>
      <!-- 滚动视差结束 -->
    </div>
    <!-- 商城结束 -->
  </div>
</template>

<script>
import {
  getProduct,
  getAllCategory,
  getFirstCategory,
  getSonCategory,
  getAllProductByCategoryId
} from "network/charity.js";
export default {
  oldUrl: "",
  name: "charityMall",
  data() {
    return {
      activeName: "",
      activeTab: "",
      categoryById: "",
      categorySon: "",
      FirstCategory: "",
      payload: [
        {
          productId: 7,
          productName: "小米手机",
          productPrice: 1999,
          productCategory: 9,
          productDetail: "为发烧而生",
          productHomeImageUrl:
            "http://wanderingdream.oss-cn-chengdu.aliyuncs.com/.jpg/20210713/30e53b00047f432f85a43b08ac8f6a69.jpg",
          createTime: null,
          status: true
        },
        {
          productId: 8,
          productName:
            "云南会泽新鲜土豆 七彩洋芋 花心大土豆 红心马铃薯 带箱10斤（乌紫）",
          productPrice: 26,
          productCategory: 15,
          productDetail: "卤菜火锅的搭档",
          productHomeImageUrl:
            "http://wanderingdream.oss-cn-chengdu.aliyuncs.com/.jpg/20210722/9fb1c57dca344591af9e43f24ad996de.jpg",
          createTime: "2021-07-22T07:15:01.000+00:00",
          status: true
        }
      ],
      str: [1, 2, 3],
      square: [1, 2, 3, 4, 5],
      category: [],
      // category: [
      //   {
      //     categoryId: 7,
      //     categoryParentId: 0,
      //     categoryTitle: "农产品",
      //     createTime: null,
      //     status: true
      //   },
      //   {
      //     categoryId: 8,
      //     categoryParentId: 0,
      //     categoryTitle: "电子产品",
      //     createTime: null,
      //     status: true
      //   }
      // ],
      carousel: [
        {
          productHomeImageUrl:
            "//imgcps.jd.com/img-cubic/creative_server_cia/v2/2000366/10025047145913/FocusFullshop/CkRqZnMvdDEvMTgxNjU5LzI5LzEzMzg3LzU2MTU1My82MGU3NDg4MEVmYTRlYzYxNC9mOTBhYjlhNGU2OThjOTE1LnBuZxIJNS10eV8wXzU2MAI47ot6QgsKB3Zpdm9YNjAQAEIZChXniannvo7popzpq5jku7fmm7Tlu4kQAUIQCgznq4vljbPmiqLotK0QAkIKCgbkvJjotKgQB1i5-_6a4qMC/cr/s/q.jpg",
          productName: "小米手机"
        },
        {
          productHomeImageUrl:
            "//imgcps.jd.com/ling4/100003134643/5bel5Lia55m-6LSn6ZKc5oOg/5Y-g5Yi4MjAw5YePMzA/p-5bd8253082acdd181d02fa3b/78854698/cr/s/q.jpg",
          productName: "大山黑牛肝菌"
        },
        {
          productHomeImageUrl:
            "//imgcps.jd.com/img-cubic/creative_server_cia/v2/2000366/100008379942/FocusFullshop/CkNqZnMvdDEvMTgzMDg2LzcvMTQxMjEvNDgyMTIxLzYwZWQzOGRlRTdmZTQxNGQ5L2QyZDAwMzcwZjgxMTViMWQucG5nEgkzLXR5XzBfNTQwAjjui3pCEwoP57K-5bel5pel6Z-p6KGoEABCEwoP5q-P5ruhNTk55YePMTgwEAFCEAoM56uL5Y2z5oqi6LStEAJCCgoG5LyY6YCJEAdYpozbx_QC/cr/s/q.jpg",
          productName: "陆良板鸭"
        },
        {
          productHomeImageUrl:
            "//imgcps.jd.com/ling4/100003134643/5bel5Lia55m-6LSn6ZKc5oOg/5Y-g5Yi4MjAw5YePMzA/p-5bd8253082acdd181d02fa3b/78854698/cr/s/q.jpg",
          productName: "云南小粒咖啡"
        }
      ]
    };
  },
  components: {},
  methods: {
    handelClick(tab, event) {
      this.getAllProductByCategoryId(tab.name);
    },
    //根据分类查询商品
    getAllProductByCategoryId(id) {
      getAllProductByCategoryId(id)
        .then(result => {
          this.categoryById = result.payload;
          // console.log(this.categoryById);
        })
        .catch(error => {});
    },
    //获取二级分类
    getSonCategory(id) {
      getSonCategory(id)
        .then(result => {
          this.categorySon = result.payload;
          this.getAllProductByCategoryId(result.payload[0].categoryId);
          this.activeTab = result.payload[0].categoryId.toString();
          // alert(this.activeName);
        })
        .catch(error => {});
    },
    // 跳转到商品详情
    // routerTo(routerPath, id) {
    //   this.$router.push({
    //     path: routerPath,
    //     query: {
    //       type: "category",
    //       id: id
    //     }
    //   });
    // },
    routerTo(routerPath, id) {
      this.$router.push({
        path: routerPath,
        query: {
          type: "category",
          id: id
        }
      });
    },
    //-----------------------------
    // routerTo(routerPath, id) {
    //   this.$router.push({
    //     path: routerPath + `/${id}`,
    //     query: {
    //       // type: "charity",
    //       id: this.payload[0].productId
    //     }
    //   });
    // },
    anchorJump(index) {
      const anchorEle = document.querySelector(`#anchor${index}`);
      if (!!anchorEle) {
        anchorEle.scrollIntoView(true); //函数详解见下
      }
    }
  },
  watch: {},
  computed: {},
  created() {
    //获取所有商品
    getProduct()
      .then(result => {
        this.payload = result.payload;
        for (let i = 1; i <= 5; i++) {
          this.carousel[i - 1] = result.payload[i];
        }

        console.log(this.carousel);
      })
      .catch(error => {});
    //获取所有分类
    getAllCategory()
      .then(result => {
        this.category = result.payload;
        // console.log("分类");
        // console.log(this.category);
      })
      .catch(error => {});
    //获取所有顶级分类
    getFirstCategory()
      .then(result => {
        this.FirstCategory = result.payload;
      })
      .catch(error => {});
  },
  mounted() {}
};
</script>

<style scoped lang="scss">
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  // background: #e5e9f2;
  background: #e9d5c6e7;
  box-shadow: 2px 2px 4px 2px rgb(180, 177, 173);
}
.bg-purple1 {
  background: #fff;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 200px;
  padding: 10px;
}
.grid-content1 {
  border-radius: 4px;
  min-height: 30px;
  font-weight: 700;
  text-align: center;
  margin-top: 3px;
  white-space: nowrap; //文字只显示一行
  overflow: hidden; //超出隐藏
  text-overflow: ellipsis; //超出部分用省略号表示
  line-height: 30px;
}
.pro_name {
  line-height: 30px;
}
.pro_price {
  color: #f78a24d0;
  line-height: 30px;
}
.row-bg {
  padding: 10px 3px;
  background-color: #f9fafc;
  margin: 10px auto;
}
.zong {
  background-color: rgb(245, 244, 244);
  padding: 20px;
  color: rgb(80, 78, 78);
  box-sizing: border-box;
  // overflow: hidden;
  width: 100%;
}
.imgbox {
  position: relative;
  // width: 180px;
  // height: 120px;
  width: 15vw;
  height: 19vh;
  margin: auto;
  overflow: hidden;
}

.imgbox .img {
  width: 15vw;
  height: 19vh;
  /* 转换速度 */
  transition: transform 1s ease;
}

.imgbox .black {
  position: absolute;
  top: 0;
  left: 0;
  width: 15vw;
  height: 19vh;
  background: rgba(44, 44, 44, 0.3);
  color: #ffffff;
  opacity: 0;
  display: flex;
  font-size: 15px;
  transition: transform 1s ease;
  margin: auto;
}
.imgbox1 {
  position: relative;
  // width: 180px;
  // height: 120px;
  width: 13vw;
  height: 19vh;
  margin: auto;
  overflow: hidden;
}

.imgbox1 .img {
  width: 13vw;
  height: 19vh;
  /* 转换速度 */
  transition: transform 1s ease;
}

.imgbox1 .black {
  position: absolute;
  top: 0;
  left: 0;
  width: 13vw;
  height: 19vh;
  background: rgba(44, 44, 44, 0.3);
  color: #ffffff;
  opacity: 0;
  display: flex;
  font-size: 15px;
  transition: transform 1s ease;
  margin: auto;
}

.black span {
  margin: auto;
}
.grid-content:hover {
  box-shadow: 0px 0px 5px 5px rgb(211, 194, 194);
  // box-shadow: none;
  // animation: top 1s forwards;
}

.imgbox a:hover .black {
  opacity: 1;
  /* 增加元素的大小*/
  transform: scale(1.1);
}

.imgbox:hover .img {
  transform: scale(1.1);
}
[class*="bg__"] {
  height: 30vh;
  font-size: 50px;
  color: rgb(94, 92, 92);
  text-align: center;
  line-height: 30vh;
  background-attachment: fixed;
  background-position: center center;
  background-size: cover;
  &:nth-child(2n) {
    box-shadow: inset 0 0 1em #111;
  }
  animation: zoomInUp 2s;
}
.bg__foo,
.bg__bar0 {
  background-image: url("../../../assets/image/charity/bg4.jpg");
}

.bg__bar1,
.bg__bar2 {
  background-image: url("../../../assets/image/charity/bg11.jpg");
}

.bg__bar3,
.bg__bar4 {
  background-image: url("../../../assets/image/charity/bg4.jpg");
}

.bg__bar5,
.bg__baz {
  background-image: url("../../../assets/image/charity/bg11.jpg");
}
.blue {
  width: 100%;
  // height: 450px;
  background-color: white;
  // overflow: auto;
}

.green {
  width: 100%;
  // height: 450px;
  background-color: #fff;
  // overflow: auto;
}
.carousel {
  position: relative;
  margin: 60px auto;
}
.carousel image {
  position: absolute;
  z-index: 1;
}
.carousel p {
  display: inline-block;
  font-size: 14px;
  padding: 10px;
  color: #e5e9f2;
  background-color: rgba(141, 88, 52, 0.5);
  position: absolute;
  bottom: 0;
  z-index: 2;
  height: 70px;
  width: 100%;
  opacity: 0;
}
// .carousel-3d-slide.current {

// }
.carousel-3d-slide.current:hover p {
  opacity: 1;
  animation: fadeInUp 1s;
  cursor: pointer;
}
// 顶部
.top {
  width: 100%;
  height: 50vh;
  background-color: rgb(254, 245, 230);
  border-radius: 8px;
  overflow: hidden;
  margin: 10px auto;
}
.top_l {
  float: left;
  height: 100%;
  width: 35vw;
}
.top_r {
  float: right;
  height: 100%;
  width: 60vw;
  background: linear-gradient(to right, #fcf5ea 10px, #dfeee1);
}
.block {
  height: 100%;
  width: 35vw;
}
.block-menu {
  display: block;
  background: rgb(254, 245, 230);
  height: 90%;
  overflow-y: scroll;
}
.block-menu div a {
  color: #fff;
  display: block;
  margin: 10px 20px;
  padding: 24px 10px;
  animation: fadeInUp 2s;
}
.three-d {
  perspective: 200px;
  cursor: pointer;
  width: 90%;
  margin: 10px auto;
}
.three-d:hover .three-d-box,
.three-d:focus .three-d-box {
  transform: translateZ(-25px) rotateX(90deg);
  display: inline-block;
}
.three-d-box {
  transition: all 0.3s ease-out;
  transform: translatez(-25px);
  transform-style: preserve-3d;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.front {
  transform: rotatex(0deg) translatez(25px);
  background: #f1e1d7;
  color: #d45703;
}
.back {
  transform: rotatex(-90deg) translatez(25px);
  color: #722d16;
  background-color: #f3efe9;
}
.front,
.back {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  padding: 15px 10px;
  box-sizing: border-box;
  border-bottom: 1px solid white;
}
.front {
  font-size: 20px;
}
.back {
  font-size: 16px;
}
h2 {
  color: #9b3b0b;
  margin: 10px;
  animation: fadeInDown 2s;
}
/deep/ .el-collapse-item__header {
  display: inline;
  line-height: 0;
}
/deep/ .el-tabs--border-card > .el-tabs__header {
  background-color: #f1e3df;
  border-bottom: 1px solid rgb(204, 161, 145);
}
/deep/ .el-tabs--border-card > .el-tabs__header .el-tabs__item {
  font-size: 20px;
}
/deep/ .el-tabs--border-card > .el-tabs__header .el-tabs__item.is-active {
  color: rgb(160, 116, 100);
}
/deep/ .el-tabs--border-card > .el-tabs__header .el-tabs__item.is-hover {
  color: rgb(160, 116, 100);
}

.el-tabs--border-card > .el-tabs__content {
  margin: 10px auto;
}

.circle {
  height: 40px;
  width: 40px;
  border-radius: 50%;
  background-color: rgba(225, 228, 233, 0.5);
  box-shadow: 0 0 1px 10px rgba(255, 255, 255, 0.7),
    0 0 1px 15px rgba(255, 255, 255, 0.4);
  // position: absolute;
  left: 100px;
  top: 100px;
  animation: changeBig 2s infinite;
  display: inline-block;
  // display: none;
}
@keyframes changeBig {
  33% {
    height: 40px;
    width: 40px;
    box-shadow: 0 0 1px 10px rgba(255, 255, 255, 0.8),
      0 0 1px 20px rgba(255, 255, 255, 0.4);
  }
  66% {
    height: 30px;
    width: 30px;
    box-shadow: 0 0 1px 5px rgba(255, 255, 255, 0.6),
      0 0 1px 10px rgba(255, 255, 255, 0.3);
  }
  100% {
    height: 40px;
    width: 40px;
    box-shadow: 0 0 1px 10px rgba(255, 255, 255, 0.7),
      0 0 1px 15px rgba(255, 255, 255, 0.4);
  }
}
.bg-text {
  width: 15vw;
  margin: 0 auto;
}
.row {
  // width: 100vw;
  margin: 0 auto;
  padding: 0 10px;
}
.row1 {
  margin: 0 auto;
  padding: 0 10px;
  height: 40vh;
}
.productBox {
  width: 20vw;
  margin: 0 40px 30px 0;
  padding: 20px;
  display: inline-block;
}
.pro {
  width: 20vw;
  margin: 0 0 30px 0;
  padding: 20px;
  display: inline-block;
}
.proB {
  margin: 10px auto;
  // text-align: center;
}
.command {
  text-align: center;
  margin-top: 20px;
  font-size: 20px;
  font-weight: bold;
  color: #722d16;
  line-height: 100%;
  // border-top: 1px solid rgb(228, 202, 195);
  // border-bottom: 1px double rgb(228, 202, 195);
}
</style>
